/*
 *  LLTimeManager_android.cpp
 *
 *
 *  Created by Alexander Trutchenko on 11/02/12.
 *  Copyright 2012 Free Team. All rights reserved.
 *
 */

#include "lid_lib/src/time_managment/LLTimeManager.h"


#include "lid_lib/src/config/LLConfig.h"
#include "lid_lib/src/config/LLKeys.h"



namespace lidlib {

////////////////////////////////////////////////////////
// utility functions


////////////////////////////////////////////////////////
//
/** LLTimeManager
 *
 */
////////////////////////////////////////////////////////

static ELLWeekDay getWeekDayFromTime(const int day)
{
	switch (day)
	{
	case 0: return ell_wd_sunday;
	case 1: return ell_wd_monday;
	case 2: return ell_wd_tuesday;
	case 3: return ell_wd_wednesday;
	case 4: return ell_wd_thursday;
	case 5: return ell_wd_friday;
	case 6: return ell_wd_saturday;
	default: break;
	}
	return ell_wd_invalid;
}

unsigned int LLTimeManager::getSeconds()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
        return now->tm_sec;
}

unsigned int LLTimeManager::getMinutes()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
        return now->tm_min;
}

unsigned int LLTimeManager::getHours()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
        return now->tm_hour;
}

unsigned int LLTimeManager::getMonthDay()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
        return now->tm_mday;
}

unsigned int LLTimeManager::getMonth()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
        return now->tm_mon + 1;
}

unsigned int LLTimeManager::getYear()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
	return now->tm_year + 1900;
}

ELLWeekDay LLTimeManager::getWeekDay()
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
	return getWeekDayFromTime(now->tm_wday);
}

////////////////////////////////////////////////////////
// Private interface

void LLTimeManager::update(float dt)
{
	time_t t = time(0);    
	struct tm* now = localtime( & t );
	
	compareTime(now->tm_sec,
				now->tm_min,
				now->tm_hour,
				now->tm_mday,
				now->tm_mon + 1,
				now->tm_year + 1900,
				getWeekDayFromTime(now->tm_wday));
}

} // namespace lidlib
